package com.budwk.app.sqfw.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

/**
 * 燃料使用情况(甲醇、乙醇、丙醇、丁烷、柴油、白油、黄油、植物油、环保油、用电、其他燃料、无)
 */
@Getter
public enum Fuel {
    JC(1, "甲醇"),
    YC(2, "乙醇"),
    BC(3, "丙醇"),
    DW(4, "丁烷"),
    CY(5, "柴油"),
    BY(6, "白油"),
    HY(7, "黄油"),
    ZWY(8, "植物油"),
    HBY(9, "环保油"),
    YD(10, "用电"),
    QT(11, "其他燃料"),
    N(12, "无");

    private Integer code;
    private String name;

    Fuel(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 通过code获取登录客户端类型
     * @param code
     * @return
     */
    public static String getName(Integer code) {
        for (Fuel o : Fuel.values()) {
            if (o.getCode() == code) {
                return o.getName();
            }
        }
        return null;
    }

    /**
     * 转string
     * @return
     */
    public static String getToString() {
        StringBuffer stringBuffer = new StringBuffer();
        for (Fuel o : Fuel.values()) {
            stringBuffer.append(o.getCode()).append("、").append(o.getName()).append(" ");
        }
        return stringBuffer.toString();
    }

    public static String getCode(String value) {
        if (StrUtil.isBlankIfStr(value)) return null;
        StringBuffer stringBuffer = new StringBuffer();
        for (Fuel o : Fuel.values()) {
            if (value.contains(o.getName())) stringBuffer.append(o.getCode()).append("、");
        }
        if (stringBuffer.length()  == 0) return null;
        return stringBuffer.substring(0, stringBuffer.lastIndexOf("、"));
    }
}
